// formPackage/components/pushImgsWidget/pushImgsWidget.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: "上传图片"
    },
    type: {
      type: String,
      value: ""
    },
    imgArr: {
      type: Array,
      value: []
    },
    //是否只能上传单张图片
    isSingle: {
      type: Boolean,
      value: false
    }
  },
  observers: {
    'imgArr': function (newValue) {
      this.setData({
        showImgArr: newValue
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    showImgArr: [],
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      if (this.properties.imgArr) {
        this.setData({
          showImgArr: this.properties.imgArr || []
        })
      }
    },
    detached: function () {

    },
  },


  /**
   * 组件的方法列表
   */
  methods: {
    //点击添加照片
    pushImgAction() {
      this.triggerEvent("pushImgAction", {
        type: this.properties.type, isSingle: this.properties.isSingle
      })
    },
    //点击了删除图片:
    cancelImgAction(e) {
      let index = e.currentTarget.dataset.index;
      this.triggerEvent("deleteImgAction", { deleteIndex: index, type: this.properties.type, isSingle: this.properties.isSingle})
    },
    //点击了预览图片:
    previewImgAction(e){
      let index = e.currentTarget.dataset.index;
      this.triggerEvent("previewImgAction", { previewIndex: index, type: this.properties.type})
    },
  }
})
